Home:ALL Converter>Comparison of datetime in where condition

Comparison of datetime in where condition

Ask Time:2018-11-16T16:10:57         Author:S..

Json Formatter

I need to add a date comparison in a query.

The field is column delivery_date timestamp without time zone

The condition should be delivery_date <= today.

I have tried :

"delivery_date < ?", Date.today 

 delivery_date.lt(Date.today)

"delivery_date" <= time.now [Error : NameError - undefined local variable or method `time' for ]

"delivery_date" <= Time.now [Error  : ArgumentError - comparison of String with DateTime failed: ]

but I am getting different errors with all.

Here is the query where I need to add my condition :

datas: tab.project
          .active
          .where("delivery_date" <= date.today, step_id: Step::OPENED, test: {typess: type})
          .joins(:test, :account)
          .group(:'account.name')
          .order('count(tab.id) DESC')
          .count(:id)

Any idea how it should be done?

Author:S..,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53333803/comparison-of-datetime-in-where-condition
yy